<script setup>
import { ref } from 'vue'
const isShow = ref(false)
</script>

<template>
  <div class="container">
    <button @click="isShow = true">展示模态框</button>

    <Teleport to="#demo" defer>
      <div class="modal" v-if="isShow">
        <div class="modal-content">
          <div class="header">用户基本信息</div>
          <div class="body">
            <p>姓名：张三，年龄：12岁</p>
          </div>
          <div class="footer">
            <button @click="isShow = false">关闭</button>
          </div>
        </div>
      </div>
    </Teleport>
  </div>
</template>

<style scoped>
.container {
  width: 200px;
  height: 200px;
  background-color: lightgreen;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 15px;
  box-sizing: border-box;
}
.modal {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
}

.modal-content {
  font-size: 12px;
  background-color: #fff;
  width: 150px;
  height: 100px;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 5px;

  .header {
    font-weight: bold;
  }
}
</style>
